package com.world.business.religious.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.world.business.religious.domain.ReligiousSect;
import com.world.business.religious.domain.query.ReligiousSectPageRequest;
import com.world.business.religious.domain.query.ReligiousSectUpdateRequest;
import com.world.business.religious.domain.vo.ReligiousSectVO;
import com.world.business.religious.service.IReligiousSectService;
import com.world.common.controller.BaseController;
import com.world.common.domain.PageResult;
import com.world.common.domain.ResponseData;
import com.world.common.domain.SuccessResponseData;
import com.world.common.enumeration.DelFlagEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 教派 前端控制器
 * </p>
 *
 * @author 邓驴
 * @since 2023-09-01
 */
@Api(tags = "教派")
@RestController
@RequestMapping("/religious/sect")
public class ReligiousSectController extends BaseController<ReligiousSect> {

    @Resource
    private IReligiousSectService religiousSectService;

    @ApiOperation("列表")
    @GetMapping("/page")
    public ResponseData<PageResult<ReligiousSectVO>> page(ReligiousSectPageRequest request) {
        Page<ReligiousSect> page = startPage(request);

        LambdaQueryWrapper<ReligiousSect> queryWrapper = Wrappers.lambdaQuery(ReligiousSect.class);
        queryWrapper.eq(ReligiousSect::getDelFlag, DelFlagEnum.NORMAL.getCode());
        Page<ReligiousSect> result = religiousSectService.page(page, queryWrapper);

        PageResult<ReligiousSectVO> pageResult = getPageResult(result, ReligiousSectVO.class);
        return new SuccessResponseData<>(pageResult);
    }

    @ApiOperation("详情")
    @GetMapping("/get/{id}")
    public ResponseData<ReligiousSectVO> get(@PathVariable("id") Long id) {
        return new SuccessResponseData<>(religiousSectService.get(id));
    }

    @ApiOperation("修改")
    @PutMapping("")
    public ResponseData<Void> update(@Validated @RequestBody ReligiousSectUpdateRequest request) {
        religiousSectService.update(request);
        return new SuccessResponseData<>();
    }


}
